<?php
/*
	This SQL query will create the table to store your object.


CREATE TABLE Hotels
(
  id int AUTO_INCREMENT PRIMARY KEY,
  name varchar(100) NOT NULL DEFAULT '',
  adress varchar (80) NOT NULL DEFAULT '',
  phone varchar (25) NOT NULL DEFAULT '',
  fax   varchar (25) NOT NULL DEFAULT '',
  citycode varchar(9)  NOT NULL DEFAULT '',
  nativeCurrency varchar(3) NOT NULL DEFAULT '', -- moneda zona nativa 
  numberOfRooms int NOT NULL DEFAULT 0,
  numberOfFloors int NOT NULL DEFAULT 0,
  checkInTime varchar(9) NOT NULL DEFAULT '',
  checkOutTime varchar(9) NOT NULL DEFAULT '',
  hightRate double(8,2) NOT NULL DEFAULT 0,
  lowRate double(8,2) NOT NULL DEFAULT 0,
  latitude  double PRECISION, 
  longitude double PRECISION,
  stars int(1),
  description text NOT NULL DEFAULT '',
  information text NOT NULL DEFAULT '',
  hotelImageId int NOT NULL,
  FOREIGN KEY (hotelImageId) REFERENCES HotelImages(id) 
    
) ENGINE=INNODB;

*/

/**
* <b>Hotels</b> class with integrated methods.
* @author Sergi Polonio Ortiz
* @version PHP5.3 MYSQL
*/
include_once('../_config/_db/_db_config.php');
class Hotels 
{
	public $id;	
	public $name;	
	public $adress;	
	public $phone;	
	public $fax;	
	public $citycode;
	public $nativeCurrency;
	public $numberOfRooms;
	public $numberOfFloors ;
	public $checkInTime;
	public $checkOutTime;
	public $hightRate;
	public $lowRate;
	public $latitude;	
	public $longitude;	
	public $stars;	
	public $description;	
	public $information;	
	public $hotelImageId;
	

	public function __construct($id='', $name='', $adress='', $phone='', $fax='', $citycode='', $nativeCurrency='', $numberOfRooms='', $numberOfFloors ='', $checkInTime='', $checkOutTime='', $hightRate='', $lowRate='', $latitude='', $longitude='', $stars='', $description='', $information='', $hotelImageId='')
	{
		$this->id = $id;
		$this->name = $name;
		$this->adress = $adress;
		$this->phone = $phone;
		$this->fax = $fax;
		$this->citycode = $citycode;
		$this->nativeCurrency = $nativeCurrency;
		$this->numberOfRooms = $numberOfRooms;
		$this->numberOfFloors  = $numberOfFloors ;
		$this->checkInTime = $checkInTime;
		$this->checkOutTime = $checkOutTime;
		$this->hightRate = $hightRate;
		$this->lowRate = $lowRate;
		$this->latitude = $latitude;
		$this->longitude = $longitude;
		$this->stars = $stars;
		$this->description = $description;
		$this->information = $information;
		$this->hotelImageId = $hotelImageId;
	}
	
  public static function getProperty($id)
  {
   $result = db::sql()->query("SELECT id,name,description,stars FROM Hotels where id =".$id);
   
    while ($row = $result->fetch_assoc()){
        $hotel = new Hotels();

        $hotel->id      = $row['id'];
        $hotel->name    = $row['name'];
        $hotel->description  = $row['description'];
        $hotel->stars  = $row['stars'];
    }
     return $hotel;
  }

  public static  function getPropertyList($id)
  {

      $result = db::sql()->query("SELECT id,name,adress,phone,fax,citycode,nativeCurrency,numberOfRooms,
                                         numberOfFloors,checkInTime,checkOutTime,hightRate,lowRate,
                                         latitude,longitude,stars,description,information,hotelImageId
                                  FROM hotels
                                  where id =".$id."
                                  order by name ");

      ////Captura de los datos recividos desde DB
    while ($row = $result->fetch_assoc()){
        $hotels = new Hotels();
        $hotels->name = $row['name'];
        $hotels->id = $row['id'];
        $hotels->information = $row['information'];
        $hotels->adress = $row['adress'];
        $hotels->phone = $row['phone'];
 

        $vHotels[] = $hotels;
    }

     return $vHotels;

  }
	
	
}

?>